# coding=utf-8
from selenium import webdriver
from public.login import Mylogin
from common.common import Common
from selenium.webdriver.common.keys import Keys
import unittest
import os
import time

class Testcontract(unittest.TestCase):

    '''
    @classmethod
    def setUpClass(self):
        self.driver = webdriver.Firefox()
        self.driver.get("http://182.92.197.48:8080/")
        self.driver.maximize_window()

    @classmethod
    def tearDownClass(self):
        self.driver.quit()
    '''


    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.get("http://182.92.197.48:8080/")
        self.driver.maximize_window()
        time.sleep(5)
        print("starttime:" + time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time())))


    def tearDown(self):
        print("endTime:" + time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time())))
        filedir = "D:/pycharm_git/test/screenshot/"
        if not os.path.exists(filedir):
            os.mkdir(filedir)
        screen_name = filedir + time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time())) + ".png"
        self.driver.get_screenshot_as_file(screen_name)
        self.driver.quit()   #这里是退出浏览器的代码，调试的时候先注释掉，调试成功再放开


    def testcontract_list_01(self):
        '''检查设置合同列表显示和隐藏的列'''
        Mylogin(self.driver).login()
        time.sleep(10)
        customer=self.driver.find_element_by_xpath('/html/body/div/section/header/div/div/div/a[2]/div')
        customer.click()  #点击客户管理
        time.sleep(10)
        self.driver.find_element_by_xpath('/html/body/div/section/section/aside/div/ul/a[8]/li/i').click()  #点击合同模块
        time.sleep(10)                    #/html/body/div[1]/section/section/main/div/div/div[2]/div[2]/div[5]/div[1]/table/thead/tr/th[20]/div/img
        self.driver.find_element_by_xpath('/html/body/div[1]/section/section/main/div/div/div[2]/div[2]/div[5]/div[1]/table/thead/tr/th[21]/div/img').click() #点击合同列表右上侧的设置按钮

        time.sleep(5)                     #/html/body/div[2]/div/div[2]/div[2]/div[1]/div[2]/div[1]/div/input
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[2]/div[2]/div[1]/div[2]/div[1]/div/input').send_keys('合同编号') #在搜索框中输入‘合同编号’
        time.sleep(5)                     #/html/body/div[2]/div/div[2]/div[2]/div[1]/div[2]/div[2]/div/div/label/span/span
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[2]/div[2]/div[1]/div[2]/div[2]/div/div/label/span/span').click() #点击合同编号前边的选择框
        time.sleep(3)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[2]/div[2]/div[2]/button[2]/span/i').click()  #点击中间部分的 向右侧移动的按钮
        time.sleep(5)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[2]/div[3]/div/button[2]/span').click()  #点击保存按钮
        # 上方演示完成后需要将隐藏的列回归原位，否则再次运行定位不到
        #下方开始断言结果

        time.sleep(5)
        list_name=self.driver.find_element_by_xpath('/html/body/div[1]/section/section/main/div/div/div[2]/div[2]/div[4]/div[1]/table/thead/tr/th[2]/div/div')
        self.assertNotIn('合同编号',list_name.text)
    def testcontract_list_02(self):
        '''检查设置合同列表高级筛选'''
        Mylogin(self.driver).login()
        time.sleep(10)
        customer=self.driver.find_element_by_xpath('/html/body/div/section/header/div/div/div/a[2]/div')
        customer.click()  #点击客户管理
        time.sleep(10)
        self.driver.find_element_by_xpath('/html/body/div/section/section/aside/div/ul/a[8]/li/i').click()  #点击合同模块
        time.sleep(5)
        self.driver.find_element_by_xpath('/html/body/div[1]/section/section/main/div/div/div[2]/div[1]/div[1]/div[2]').click() #点击高级筛选
        time.sleep(5)
        self.driver.find_element_by_xpath("//input[@class='el-input__inner' and @placeholder='请选择要筛选的字段名']").click() #点击第一个下拉框
        time.sleep(5)
        self.driver.find_element_by_xpath("//li/span[text()='客户名称']").click() # 点击选择‘客户名称’
        time.sleep(3)
        self.driver.find_element_by_xpath("//input[@class='el-input__inner' and @autocomplete='off' and @placeholder='请输入筛选条件']").send_keys('赵一四')  #在搜索框中输入 赵一四
        time.sleep(3)
        self.driver.find_element_by_xpath('/html/body/div[1]/section/section/main/div/div/div[2]/div[1]/div[1]/div[3]/div/div[3]/div/button[2]/span').click()  #点击确定按钮



        # 上方演示完成后需要将隐藏的列回归原位，否则再次运营会定位不到
        #下方开始断言结果

        time.sleep(5)
        serach_name=self.driver.find_element_by_xpath('/html/body/div[1]/section/section/main/div/div/div[2]/div[1]/div[2]/ul/li/span')
        self.assertIn('客户名称 等于“赵一四”',serach_name.text)



if __name__ == "__main__":
    unittest.main()
